package my.test.factoryMethodPattern.singletonFactory;

import java.lang.reflect.Constructor;

public class SingletonFactory {
    private static Singleton singleton;

    static {
       try {
           Class c1 = Class.forName(Singleton.class.getName());
           //获得无参构造
           Constructor constructor = c1.getDeclaredConstructor();
           //设置无参构造是可访问的
           constructor.setAccessible(true);
           //产生一个实例对象
           singleton = (Singleton) constructor.newInstance();
       } catch (Exception e) {

       }
    }

    public static Singleton getSingleton() {
        return singleton;
    }
}
